package com.bangcle.library.ui.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.widget.Checkable;
import android.widget.CheckedTextView;
import android.widget.FrameLayout;
/**
 * 类似CheckedTextView，可带（前/后/左/右）图标，且紧跟文字显示
 *<com.bangcle.pocdemo.core.view.IconTextView
 *           android:id="@+id/mHouseType"
 *           android:layout_width="0dp"
 *           android:layout_height="match_parent"
 *           android:layout_weight="1"
 *           android:drawablePadding="5dp"
 *           android:drawableRight="@drawable/ic_sort_selector"
 *           android:singleLine="true"
 *           android:checked="true"
 *           android:text="新房"
 *           android:textColor="@color/proj_item_checked_1"
 *           android:textSize="@dimen/textSizeMiddle" /> 
 *
 * @author luchyu
 * */

public class IconTextView extends FrameLayout implements Checkable {
    private CheckedTextView mCheckedTextView;

    public IconTextView(Context context) {
        super(context);
        this.initialize(context, null, 0);
    }

    public IconTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.initialize(context, attrs, 0);
    }

    public IconTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.initialize(context, attrs, defStyleAttr);
    }

    protected void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
        this.setClickable(true);
        this.mCheckedTextView = new CheckedTextView(context, attrs, defStyleAttr);
        this.mCheckedTextView.setPadding(0, 0, 0, 0);
        this.mCheckedTextView.setBackgroundDrawable(null);
        this.mCheckedTextView.setDuplicateParentStateEnabled(true);
        super.addView(mCheckedTextView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    }
    public void setTextColor(int colors) {
        mCheckedTextView.setTextColor(colors);
    }
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
    public void setText(CharSequence mText) {
        mCheckedTextView.setText(mText);
    }
    @Override
    public void setChecked(boolean checked) {
        mCheckedTextView.setChecked(checked);
    }

    @Override
    public boolean isChecked() {
        return mCheckedTextView.isChecked();
    }

    @Override
    public void toggle() {
        mCheckedTextView.toggle();
    }

    public void setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) {
        mCheckedTextView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
    }

    public void setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) {
        mCheckedTextView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
    }
}
